
#include "testApp.h"




void testApp::setup(){

    panel1 = new sxPanelWidget();
    panel1->setName("MyPanel");
    panel1->setPosition(200,500);
    panel1->setShape(300, 200);
    panel1->setPivot(150,100,0);
    scene->addChild(panel1);

    sxButtonWidget* button1 = new sxButtonWidget();
    button1->setName("Reset Rotation");
    button1->setPosition(500,600);
    button1->setShape(200, 40);
    button1->setPivot(100,25,0);
    button1->setPosition(150,50);
    button1->addEventHandler(this);
    panel1->addChild(button1);

    slider1 = new sxSliderWidget();
    slider1->setName("Rotation");
    slider1->setShape(240, 40);
    slider1->setPosition(30,100);
    slider1->setValueMin(-3.14f);
    slider1->setValueMax(3.14f);
    slider1->addEventHandler(this);
    panel1->addChild(slider1); 

    slider2 = new sxSliderWidget();
    slider2->setName("Scale");
    slider2->setShape(400, 40);
    slider2->setPivot(200,20,0);
    slider2->setPosition(450,500);
    slider2->addRotationZ(3.14/2);
    slider2->setValueMin(0.0f);
    slider2->setValueMax(2.0f);
    slider2->addEventHandler(this);
    scene->addChild(slider2); 

    textbox1 = new sxTextShape();
    textbox1->setName("MyTextfield");
    textbox1->setText("So, this is the sx widget example. It demonstrates how to use basic widgets like the sxSlider. Adding and placing them in the scene is pretty straight forward. It is also interesting to know that they can be nested into each other. The checkbox, for example, is nested into the textbox therefore always moving along with it. \n\nThe easist way to handle events from these basic widgets is in the sxApp. A button, for example, has a widgetButton(...) handler in the app class.");
    textbox1->setPadding(20.0f);
    textbox1->setShape(300, 300);
    textbox1->setPosition(700,500);
    textbox1->setPivot(150,150,0);
    scene->addChild(textbox1);
    
    checkbox1 = new sxCheckboxWidget();
    checkbox1->setName("Make Text Red");
    checkbox1->setShape(180, 40);
    checkbox1->setPosition(0,-50);
    checkbox1->addEventHandler(this);
    textbox1->addChild(checkbox1);   
}

void testApp::update(){}
void testApp::exit(){}
void testApp::resized( int w, int h ){}


void testApp::keyPress( sxKey& key ){}
void testApp::keyRelease( sxKey& key ){}


void testApp::mousePress( sxMouse& mouse ){}
void testApp::mouseRelease( sxMouse& mouse ){}
void testApp::mouseMove( sxMouse& mouse ){}
void testApp::mouseDrag( sxMouse& mouse ){}
void testApp::mouseScroll( sxMouse& mouse ){}
void testApp::mouseDoubleclick( sxMouse& mouse ){}


void testApp::touchDown( sxTouch& touch ){}
void testApp::touchUp( sxTouch& touch ){}
void testApp::touchMove( sxTouch& touch ){}


void testApp::penPressure( sxPen& pen ){}
void testApp::penOrientation( sxPen& pen ){}
void testApp::penEnter( sxPen& pen ){}
void testApp::penLeave( sxPen& pen ){}


void testApp::widgetButton( sxButtonWidget& button ) {
    if (button.getName() == "Reset Rotation") {
        slider1->setValue(0.0f);
    } else if (button.getName() == "MySuperButton2") {
        textbox1->setShape(textbox1->getWidth()+20, 300); 
    }
}
void testApp::widgetSlider( sxSliderWidget& slider ) {
    if (&slider == slider1) {
        textbox1->resetRotation();
        textbox1->addRotationZ(-slider.getValue());
    } else if (&slider == slider2) {
        panel1->setScale(slider.getValue());  
        textbox1->setScale(slider.getValue());    
    }
}
void testApp::widgetCheckbox( sxCheckboxWidget& checkbox ) {
    if (&checkbox == checkbox1) {
        if( checkbox.getValue() ) {
            textbox1->setColor(1.0f, 0.0f, 0.0f, 1.0f);
        } else {
            textbox1->setColor(1.0f, 1.0f, 1.0f, 1.0f);
        }
    }
}



